# import numpy as np
# import matplotlib.pyplot as plt
#
# # 假设我们有20个示例和5个算法的结果
# num_examples = 20
# num_algorithms = 5
#
# # 生成随机数据（假设每个算法在每个示例上的适应度值）
# # 实际应用中应替换为真实的算法运行结果
# np.random.seed(42)
# results = np.random.rand(num_examples, num_algorithms) * 100  # 形状为 (20, 5)
#
# # 算法名称
# algorithms = ["Genetic Algorithm", "Particle Swarm Optimization", "Simulated Annealing",
#               "Ant Colony Optimization", "Differential Evolution"]
#
# # 示例名称（假设为Test Function 1到20）
# examples = [f"TF {i+1}" for i in range(num_examples)]
#
# # 绘制折线图
# plt.figure(figsize=(15, 8))
#
# # 为每个算法绘制折线图
# for i in range(num_algorithms):
#     plt.plot(examples, results[:, i], marker='o', label=algorithms[i], linewidth=2)
#
# # 设置图表样式
# plt.title("Algorithm Performance Comparison Across 20 Test Functions", fontsize=16)
# plt.xlabel("Test Functions", fontsize=14)
# plt.ylabel("Fitness Value", fontsize=14)
# plt.xticks(rotation=45, fontsize=12)  # 旋转横轴标签
# plt.legend(fontsize=12)
# plt.grid(True, linestyle='--', alpha=0.7)
# plt.tight_layout()
# plt.show()

import matplotlib.pyplot as plt
import numpy as np

# 生成模拟数据
instances = np.arange(1, 21)  # 20 个实例
algorithms = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6']
results = np.random.rand(6, 20)  # 6 行 20 列的随机结果

# 绘制折线图
plt.figure(figsize=(12, 8))
for i in range(6):
    plt.plot(instances, results[i], marker='o', label=algorithms[i])

plt.xlabel("Instance")
plt.ylabel("Objective Value")
plt.legend()
plt.title("Comparison of 6 Algorithms on 20 Instances")
plt.grid()
plt.show()
